package com.liuyc.lib.ui.nestedScroll

import android.content.Context
import android.util.AttributeSet
import androidx.annotation.AttrRes
import androidx.recyclerview.widget.RecyclerView
import java.util.*

class ChildNestedRecycleView :  RecyclerView {

    private val mScrollListeners: MutableList<OnScrollListener> by lazy {
        arrayListOf<OnScrollListener>()
    }

    constructor(context: Context) : super(context) {}
    constructor(
            context: Context, attrs: AttributeSet?
    ) : super(context, attrs) {
    }

    constructor(
            context: Context, attrs: AttributeSet?,
            @AttrRes defStyleAttr: Int
    ) : super(context, attrs, defStyleAttr) {
    }


    override fun addOnScrollListener(listener: OnScrollListener) {
//        super.addOnScrollListener(listener)
        mScrollListeners.add(listener)
    }

    fun setScrollState(state: Int){
        if (mScrollListeners != null) {
            for (i in mScrollListeners.indices.reversed()) {
                mScrollListeners[i].onScrollStateChanged(this, state)
            }
        }
    }

}